package com.ericzong.util.ui;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Toolkit;

public class LocationUtils
{

    public static void setFrameCenter(Frame frame)
    {
        frame.setLocationRelativeTo(null);
    }

    public static void setFrameCenter2(Frame frame)
    {
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (dim.width - frame.getWidth()) / 2;
        int y = (dim.height - frame.getHeight()) / 2;
        frame.setLocation(x, y);
    }

    public static void setFrameCenter3(Frame frame)
    {
        Point point = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
        int x = point.x - frame.getWidth() / 2;
        int y = point.y - frame.getHeight() / 2;
        frame.setLocation(x, y);
    }

    public static void setFrameSizeByScreenRatio(Frame frame, double widthRatio, double heightRatio)
    {
        Dimension dim = getScreenSize();
        int width = (int) (dim.width * widthRatio);
        int height = (int) (dim.height * heightRatio);
        frame.setSize(width, height);
    }

    public static void setFrameSizeByScreenRatio(Frame frame, double ratio)
    {
        setFrameSizeByScreenRatio(frame, ratio, ratio);
    }

    public static Dimension getScreenSize()
    {
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        return dim;
    }

}
